﻿using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Verse;

namespace Miao.Stand
{
    public class Need_StandPower : Need_Seeker
    {
        public StandPawn Stand
        {
            set
            {
                stand = value;
                maxLevel = stand.persistence;
            }
        }
        public override string GetTipString()
        {
            return base.LabelCap + ": " + base.CurLevelPercentage.ToStringPercent() + " (" + CurLevel.ToString("0.##") + " / " + MaxLevel.ToString("0.##") + ")\n" + def.description;
        }
        private StandPawn stand;
        public Need_StandPower(Pawn pawn) : base(pawn)//要有效果，只能写回调了
        {

        }
        private float maxLevel = 2;

         public override float MaxLevel => maxLevel;//A级是5，B级是4
      
        //public override float CurInstantLevel
        //{
        //    get
        //    {
        //        return LevelFrom(CurrentInstantBeauty());
        //    }
        //}
        //private float LevelFrom(float currentlevel)
        //{
        //    return Mathf.Clamp01(def.baseLevel + currentlevel * 0.1f);
        //}
        public override int GUIChangeArrow
        {
            get
            {
                switch(levelSpeed)
                {
                    case 1:
                        return 1;
                    case 10:
                        return 2;
                    case -1:
                        return -1;
                    case -10:
                        return -2;
                }
                return 0;
            }
        }
        bool FastRecovery;
        public int levelSpeed = 1;


        //需求鉴定间隔
        public override void NeedInterval()
        {
            stand.LevelSpeedChange();
            CurLevel -= def.fallPerDay * 0.025f* levelSpeed;
        }
        public override void ExposeData()
        {
            base.ExposeData();
            Scribe_References.Look<StandPawn>(ref stand, "stand");
            Scribe_Values.Look<int>(ref levelSpeed, "SpeedArrow");
            if (stand != null && Scribe.mode == LoadSaveMode.ResolvingCrossRefs)
            {
                maxLevel = stand.persistence;
            }
        }

        /// <summary>
        /// 能量花费是否足够
        /// </summary>
        /// <param name="cost"></param>
        /// <returns></returns>
        public bool PowerConsumePeek(float cost)
        {
            if (CurLevel < cost)
            {
                return false;
            }
            return true;
        }
        /// <summary>
        /// 能量扣除
        /// </summary>
        /// <param name="cost"></param>
        /// <returns></returns>
        public bool PowerConsume(float cost)
        {
            CurLevel -= cost;
            if (CurLevel > cost)
            {
                return true;
            }
            return false;
        }
    }
}
